#include "StdAfx.h"
#include ".\doublefunctionset.h"


void DoubleFunctionSet ::initTypes(){
		   insert(*(Ty_Double   = new AtomicType("D")));

		   insert(*(Ty_Boolean = new AbstractType(
					ArrowType(
						_TYPE(*Ty_Double), 
						ArrowType(
							_TYPE(*Ty_Double),
							_TYPE(*Ty_Double))), _TYPE(*Ty_Double), "Boolean")));
	}

void DoubleFunctionSet ::initNumbers(){
	COUNTER size = 10;
	char c[2] = "0";
	for(COUNTER i=0; i<size; i++){		  
		  Constants.push_back(new FreeTermVariable(_TYPE(*Ty_Double), c));
		  insert(*(Constants[i]));
		  c[0]  += 1;
		}
	}

void DoubleFunctionSet ::initBooleans(){
	AtomicType Ty_Temp("o");
	FreeTermVariable Ter_Temp(Ty_Temp,"o");

			Te_True = new AbstractTypeTerm (
				AbstractTerm(AbstractTerm(Ter_Temp, FreeTermVariable(Ty_Temp)), Ter_Temp), 
				Ty_Temp,
				"True");	 
			((Term*)Te_True)->setTypeSyntax(Ty_Boolean->getSyntax());
			insert(*(Te_True));
			

			Te_False = new AbstractTypeTerm (
				AbstractTerm(AbstractTerm(Ter_Temp,Ter_Temp),Ter_Temp),
				Ty_Temp,
				"False");
			((Term*)Te_False)->setTypeSyntax(Ty_Boolean->getSyntax());
			insert(*(Te_False));
	}
void DoubleFunctionSet ::initBooleanOperators(){
	   
	FreeTermVariable x1(_TYPE(*Ty_Boolean));
	FreeTermVariable x2(_TYPE(*Ty_Boolean));
	
	ApplicationTerm Temp1(   
				ApplicationTerm(
										ApplicationTerm(x1, _TYPE(*Ty_Boolean)),
										x2) ,
				_TERM(*Te_False));
	   Te_And = new AbstractTerm(AbstractTerm(Temp1, x2), x1, "And");
	   insert(*Te_And);
	   
	   ApplicationTerm Temp2(   
				ApplicationTerm(
										ApplicationTerm(x1, _TYPE(*Ty_Boolean)),
										_TERM(*Te_False)) ,
				_TERM(*Te_True));
	   Te_Not = new AbstractTerm(Temp2, x1, "Not");
	   insert(*Te_Not);

	   ApplicationTerm Temp3(   
				ApplicationTerm(
										ApplicationTerm(x1, _TYPE(*Ty_Boolean)),
										_TERM(*Te_True)) ,
				x2);
	   Te_Or = new AbstractTerm(AbstractTerm(Temp3, x2), x1, "Or");
	   insert(*Te_Or);	
	}

void DoubleFunctionSet ::initBinaryFunctions( ){
	  insert(*(Te_Plus   = new FreeTermVariable(
						ArrowType(_TYPE(*Ty_Double) , 
						ArrowType(_TYPE(*Ty_Double),  _TYPE(*Ty_Double))), "+")));

	   insert(*(Te_Mult  = new FreeTermVariable(
						ArrowType(_TYPE(*Ty_Double) , 
						ArrowType(_TYPE(*Ty_Double),  _TYPE(*Ty_Double))), "*")));


	    insert(*(Te_Div  = new FreeTermVariable(
						ArrowType(_TYPE(*Ty_Double) , 
						ArrowType(_TYPE(*Ty_Double),  _TYPE(*Ty_Double))), "/")));

	    insert(*(Te_Gt  = new FreeTermVariable(
						ArrowType(_TYPE(*Ty_Double) , 
						ArrowType(_TYPE(*Ty_Double),  _TYPE(*Ty_Boolean))), ">")));


	}



DoubleFunctionSet ::~DoubleFunctionSet (void)
{
	delete Ty_Boolean;
	delete Te_False;
	delete Te_True;
	delete Te_And;
	delete Te_Not;
	delete Te_Or;

	for(size_t i=0; i<Constants.size( ); i++)
		delete Constants[i];
	Constants.clear( );


}
